<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="visible"
      width="60%"
      append-to-body
      custom-class="import-dialog"
    >
      <div class="app-container">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="68px"
        >
          <el-form-item label="模板编号" prop="templateId">
            <el-input
              v-model="queryParams.templateId"
              placeholder="请输入模板编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="模板名称" prop="templateName">
            <el-input
              v-model="queryParams.templateName"
              placeholder="请输入模板名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <!-- <el-form-item label="状态" prop="usageStatus">
            <el-select
              v-model="queryParams.usageStatus"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="dict in statusList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item> -->
          <el-form-item label="创建时间">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
        <el-table
          v-loading="loading"
          :data="list"
          @selection-change="handleSelectionChange"
          ref="table"
        >
          <!-- <el-table-column type="selection" width="55" align="center" /> -->
          <el-table-column label="模板编号" align="center" prop="templateId" />
          <el-table-column
            label="模板名称"
            align="center"
            prop="templateName"
          />
          <el-table-column label="申请人信息" align="center" prop="createName">
            <template slot-scope="scope">
              <span>
                {{ scope.row.createName }} - {{ scope.row.createMobile }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="适应租期" align="center" prop="apartmentType">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.dict_unsubscribe_rule_type"
                :value="scope.row.apartmentType"
              />
            </template>
          </el-table-column>
          <!-- <el-table-column label="启用" align="center" prop="usageStatus">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.usageStatus"
                active-value="1"
                inactive-value="0"
                @change="handleStatusChange(scope.row)"
              ></el-switch>
            </template>
          </el-table-column> -->
          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ formatDate(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleDetail(scope.row)"
                v-hasPermi="['contract:template:detail']"
                >详情</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['contract:template:edit']"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['contract:template:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="select(scope.row)"
                >选择</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </el-dialog>
  </div>
</template>

  <script>
import {
  listContractTemplate,
  getContractTemplateStatistics,
  delContractTemplate,
  changeUsageStatus,
  getContractTemplate,
} from "@/api/contract/template";
export default {
  props: {
    title: {
      default: "选择模板模板",
    },
    value: {
      default: false,
    },
  },
  dicts: [
    "dict_unsubscribe_rule_type",
    "dict_cancel_type",
    "dict_enable_status",
  ],
  data() {
    return {
      visible: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        templateId: undefined,
        templateName: undefined,
        // usageStatus: undefined,
        usageStatus: 1,
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      //列表
      list: [],
      //状态列表
      statusList: [
        { label: "启用", value: "1" },
        { label: "禁用", value: "0" },
      ],
    };
  },
  filters: {
  },
  computed: {
  },
  watch: {
    value(newVal, oldVal) {
      if (newVal) {
        this.init();
      }
      this.visible = newVal; // 监测value的变化，并赋值。
    },
    visible(val) {
      this.$emit("input", val); // 此处监测visible目的为关闭弹窗时，重新更换value值，注意emit的事件一定要为input。
    },
  },
  methods: {
    init() {
      this.getList();
    },
    handleQuery() {
      this.getList();
    },
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listContractTemplate(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    handleSelectionChange() {},
    select(item) {
      this.$emit("success", item);
      this.close();
    },
    close() {
      this.resetQuery();
      this.visible = false;
    },
  },
};
</script>

  <style lang="scss" scoped>
</style>
